package se19team1e.entity;

import java.util.Date;

import se19team1e.dao.abstrakt.generics.DataTransferObject;
import se19team1e.util.ComparisonUtils;
import se19team1e.util.ReflectionUtils;

/**
 * Represents the Job Advert object in the system.
 * 
 * <p>
 * It is a concrete class that implements the DataTransferObject.
 * Generic template <T> is defined as JobAdvertDTO
 * </p>
 * 
 * @see CreateJobAdvertController , WithdrawJobAdvertController
 * @author lai shiaw san
 * 
 */
@SuppressWarnings("serial")
public class JobAdvertDTO implements DataTransferObject<JobAdvertDTO> {

	/**
	 * JobAdvert title.
	 */
	private String title;

	/**
	 * JobAdvert description.
	 */
	private String description;

	/**
	 * JobAdvert skills.
	 */
	private String skills;

	/**
	 * JobAdvert experience.
	 */
	private String experience;

	/**
	 * JobAdvert salary.
	 */
	private double salary;

	/**
	 * JobAdvert start date.
	 */
	private Date startDate;

	/**
	 * JobAdvert location.
	 */
	private String location;

	/**
	 * JobAdvert company id.
	 */
	private String companyId;

	/**
	 * JobAdvert use company description instead.
	 */
	private boolean useCompanyDescription;

	/**
	 * JobAdvert department id.
	 */
	private String departmentId;

	/**
	 * JobAdvert object id.
	 */
	private String id;

	/**
	 * JobAdvert advertiser id.
	 */
	private String advertiserId;

	/**
	 * JobAdvert withdrawn flag.
	 */
	private boolean withdrawn;
	/**
	 * JobAdvert flag if job advert is deleted
	 */
	private boolean deleted;
	/**
	 * Job Advert department name , if any
	 */
	private String departmentName;
	/**
	 * Job Advert company name that it is associated to
	 */
	private String companyName;

	/**
	 * Gets the job advertisement (jobadvert) title.
	 * 
	 * @return JobAdvert title.
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * Sets the new job advertisement title.
	 * 
	 * @param title
	 *            New JobAdvert title.
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * Gets the JobAdvert description of the work.
	 * 
	 * @return JobAdvert description.
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Sets the new JobAdvert description of the work.
	 * 
	 * @param description
	 *            New JobAdvert description.
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the JobAdvert company description which is same as company
	 * description.
	 * 
	 * @return flag to use company description.
	 */
	public boolean isUseCompanyDescription() {
		return useCompanyDescription;
	}

	/**
	 * Sets the new JobAdvert flag to use company description.
	 * 
	 * @param useCompanyDescription
	 *            New JobAdvert flag to use company description.
	 */
	public void setUseCompanyDescription(boolean useCompanyDescription) {
		this.useCompanyDescription = useCompanyDescription;
	}

	/**
	 * Gets the JobAdvert skills required for the job.
	 * 
	 * @return JobAdvert skills.
	 */
	public String getSkills() {
		return skills;
	}

	/**
	 * Sets the new JobAdvert skills required for the job.
	 * 
	 * @param skills
	 *            New JobAdvert skills.
	 */
	public void setSkills(String skills) {
		this.skills = skills;
	}

	/**
	 * Gets the JobAdvert number of years of experience.
	 * 
	 * @return JobAdvert experience.
	 */
	public String getExperience() {
		return experience;
	}

	/**
	 * Sets the new JobAdvert number of years of experience.
	 * 
	 * @param experience
	 *            New JobAdvert experience.
	 */
	public void setExperience(String experience) {
		this.experience = experience;
	}

	/**
	 * Gets the JobAdvert employment start date.
	 * 
	 * @return JobAdvert start date.
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * Gets the JobAdvert salary.
	 * 
	 * @return salary for the job
	 */
	public double getSalary() {
		return salary;
	}

	/**
	 * Sets the new JobAdvert salary.
	 * 
	 * @param salary
	 *            salary for the job
	 */
	public void setSalary(double salary) {
		this.salary = salary;
	}

	/**
	 * Sets the new JobAdvert employment start date.
	 * 
	 * @param startDate
	 *            New JobAdvert employment start date.
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * Gets the JobAdvert location of employment.
	 * 
	 * @return JobAdvert location of employment.
	 */
	public String getLocation() {
		return location;
	}

	/**
	 * Sets the new JobAdvert location of employment.
	 * 
	 * @param location
	 *            New JobAdvert location of employment.
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * Gets the JobAdvert company id. companyId is a unique value.
	 * 
	 * @return JobAdvert company id.
	 */
	public String getCompanyId() {
		return companyId;
	}

	/**
	 * Sets the new JobAdvert company id. companyId is unique for each company.
	 * 
	 * @param companyId
	 *            New JobAdvert company id.
	 */
	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	/**
	 * Gets the JobAdvert department id. departmentId is a unique value.
	 * 
	 * @return JobAdvert department id.
	 */
	public String getDepartmentId() {
		return departmentId;
	}

	/**
	 * Sets the new JobAdvert department id. departmentId is unique for each
	 * department.
	 * 
	 * @param departmentId
	 *            New JobAdvert department id.
	 */
	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}

	/**
	 * Sets the new JobAdvert id. id is unique for each job advert.
	 * 
	 * @param id
	 *            New JobAdvert id.
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * Gets the JobAdvert advertiser id. advertiserId is a unique value.
	 * 
	 * @return advertiserId Returns the jobAdvert advertiser id.
	 */
	public String getAdvertiserId() {
		return advertiserId;
	}

	/**
	 * Sets the new JobAdvert advertiser id. advertiserId is unique for each
	 * advertiser.
	 * 
	 * @param advertiserId
	 *            New JobAdvert advertiser id.
	 */
	public void setAdvertiserId(String advertiserId) {
		this.advertiserId = advertiserId;
	}

	/**
	 * Gets the Job Advert withdrawn flag to check job advert is withdrawn.
	 * 
	 * @return withdrawn Job Advert withdrawn flag.
	 */
	public boolean isWithdrawn() {
		return withdrawn;
	}

	/*
	 * public String toString() {
	 * 
	 * StringBuilder stringBuilder = new StringBuilder();
	 * 
	 * Field fields[] = this.getClass().getDeclaredFields();
	 * 
	 * for (Field field : fields) { field.setAccessible(true); try {
	 * stringBuilder.append(field.getName() + "=" + field.get(this)+ "\n"); }
	 * catch (Exception e) { e.printStackTrace(); } } return
	 * stringBuilder.toString(); }
	 */
	/**
	 * To obtain the string value for Job Advert Obtained when convert fields in
	 * a property file into a String
	 * 
	 * @return string value
	 */
	@Override
	public String toString() {
		return (ReflectionUtils.toString(this));
	}

	/**
	 * Set the flag to delete for Job Advert
	 */
	@Override
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	/**
	 * Check if the Job Advert is deleted
	 * 
	 * @return deleted If Job Advert is deleted, it is true
	 */
	@Override
	public boolean isDeleted() {
		return deleted;
	}

	/**
	 * Set the id for an Job Advert
	 * 
	 * @param object
	 *            id is assume to be a string and converted and set to object
	 */
	@Override
	public void setId(Object id) {
		this.id = (String) id;
	}

	/**
	 * Obtain the id for an Job Advert
	 * 
	 * @return the id for the Job Advert
	 */
	@Override
	public String getId() {
		return id;
	}

	/**
	 * Get the department Name for the Job Advert
	 * 
	 * @return departmentName Gets the department name of the Job Advert
	 */
	public String getDepartmentName() {
		return departmentName;
	}

	/**
	 * Withdraws the job advert by setting the withdraw boolean flag as true
	 */
	public void withdraw() {
		this.withdrawn = true;
	}

	/**
	 * Set the department name of the Job Advert
	 * 
	 * @param departmentName
	 *            Department name of the Job Advert to be set
	 */
	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	/**
	 * Get the company Name for the Job Advert
	 * 
	 * @return companyName Gets the company name of the Job Advert
	 */
	public String getCompanyName() {
		return companyName;
	}

	/**
	 * Set the company name of the Job Advert
	 * 
	 * @param companyName
	 *            company name of the Job Advert to be set
	 */
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		// implemented only for junit testing, purpose of assessment
		if (obj instanceof JobAdvertDTO) {
			JobAdvertDTO other = (JobAdvertDTO) obj;
			return ComparisonUtils.equals(title, other.title)
					&& ComparisonUtils.equals(description, other.description)
					&& ComparisonUtils.equals(skills, other.skills)
					&& ComparisonUtils.equals(experience, other.experience)
					&& ComparisonUtils.equals(salary, other.salary)
					&& ComparisonUtils.equals(startDate, other.startDate)
					&& ComparisonUtils.equals(location, other.location)
					&& ComparisonUtils.equals(companyId, other.companyId)
					&& ComparisonUtils.equals(useCompanyDescription,
							other.useCompanyDescription)
					&& ComparisonUtils.equals(departmentId, other.departmentId)
					&& ComparisonUtils.equals(id, other.id)
					&& ComparisonUtils.equals(advertiserId, other.advertiserId)
					&& ComparisonUtils.equals(withdrawn, other.withdrawn)
					&& ComparisonUtils.equals(deleted, other.deleted)
					&& ComparisonUtils.equals(departmentName,
							other.departmentName)
					&& ComparisonUtils.equals(companyName, other.companyName);
		}

		return false;
	}

}
